package com.sundablog.controller.systemsetup.permissionsmanage.user;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sundablog.pojo.AdminUser;
import com.sundablog.result.BaseResult;
import com.sundablog.result.LayUiResult;
import com.sundablog.result.MenuResult;
import com.sundablog.service.systemsetup.permissionsManage.user.UserService;

import cn.hutool.core.util.StrUtil;

/**
 * 用户管理控制器类
 * @ClassName:  UserController   
 * @Description:TODO(这里用一句话描述这个类的作用)   
 * @author: 哒哒 
 * @date:   2018年3月5日 下午12:30:34   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@Controller
@RequestMapping("/systemsetup/permissionsmanage/user/")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 显示管理员界面
	 * @Title: showIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_showIndex")
	@RequestMapping("/showIndex")
	public String showIndex() {	
		return "/systemsetup/permissionsmanage/user/index";
	}
	/**
	 * 分页查询
	 * @Title: findPagingQuery   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param page
	 * @param: @param limit
	 * @param: @return      
	 * @return: LayUiResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_findPagingQuery")
	@RequestMapping("/findPagingQuery")
	@ResponseBody
	public LayUiResult findPagingQuery(@RequestParam(value="page", defaultValue="1") int page,@RequestParam(value="limit", defaultValue="10") int limit) {
		LayUiResult layUiResult = userService.findPagingQuery(page, limit);
		
		return layUiResult;
	}
	
	/**
	 * 添加界面显示
	 * @Title: addIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_addIndex")
	@RequestMapping("/addIndex")
	public String addIndex() {
		return "/systemsetup/permissionsmanage/user/add";
	}
	
	/**
	 * 添加一个管理员用户
	 * @Title: addUser   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param adminUser
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_addUser")
	@RequestMapping("/addUser")
	@ResponseBody
	public BaseResult addUser(AdminUser adminUser,int roleId) {
		if (StrUtil.isEmpty(adminUser.getAvatar())) {
			return BaseResult.build(201,"请上传头像");
		}
		int i = userService.addUser(adminUser,roleId);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.addSuccess);
		} else {
			return BaseResult.build(209, BaseResult.addFail);
		}
	}
	
	/**
	 * 删除管理员用户
	 * @Title: delectAdminUser   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_delectAdminUser")
	@RequestMapping("/delectAdminUser")
	@ResponseBody
	public BaseResult delectAdminUser(int id) {
		int i = userService.delectAdminUser(id);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.delectSuccess);
		} else {
			return BaseResult.build(209, BaseResult.delectFail);
		}
	}
	
	/**
	 * 禁用管理员用户
	 * @Title: updataDisableAdminUser   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_updataDisableAdminUser")
	@RequestMapping("/updataDisableAdminUser")
	@ResponseBody
	public BaseResult updataDisableAdminUser(int id) {
		int i = userService.updataDisableAdminUser(id);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(209, BaseResult.updataFail);
		}
	}
	
	/**
	 * 修改管理员性别接口
	 * @Title: updataAdminUserSex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_updataAdminUserSex")
	@RequestMapping("/updataAdminUserSex")
	@ResponseBody
	public BaseResult updataAdminUserSex(int id) {
		int i = userService.updataAdminUserSex(id);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(209, BaseResult.updataFail);
		}
	}
	
	/**
	 * 根据id获取管理员数据
	 * @Title: selectAdminUserById   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_selectAdminUserById")
	@RequestMapping("/selectAdminUserById")
	@ResponseBody
	public BaseResult selectAdminUserById(int id) {
		AdminUser adminUser = userService.selectAdminUserById(id);
		return BaseResult.build(200, "", adminUser);
	}
	
	/**
	 * 修改数据
	 * @Title: updataAdminUser   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param adminUser
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_updataAdminUser")
	@RequestMapping("/updataAdminUser")
	@ResponseBody
	public BaseResult updataAdminUser(AdminUser adminUser) {
		int i = userService.updataAdminUser(adminUser);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(200, BaseResult.updataFail);
		}
	}
	
	
	/**
	 * 查看界面显示
	 * @Title: detailIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_detailIndex")
	@RequestMapping("/detailIndex")
	public String detailIndex() {
		return "/systemsetup/permissionsmanage/user/detail";
	}
	
	/**
	 * 修改界面显示
	 * @Title: editIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_user_editIndex")
	@RequestMapping("/editIndex")
	public String editIndex() {
		return "/systemsetup/permissionsmanage/user/edit";
	}
	
	
}
